﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using TecBaseObjects.Models;
using TpOffice.Controller;
using TpOffice.Interfaces;

namespace TpOffice.Forms {

    public partial class ImportBMDForm : Form, ITecForm {

        #region Members

        ImportBMDController controller;

        #endregion

        #region Constructor

        public ImportBMDForm() {
            this.controller = new ImportBMDController(this);
            InitializeComponent();
        }

        #endregion

        #region Properties

        public List<ImportBMDModel> MyModel {
            get;
            set;
        }

        #endregion

        #region Methods

        private void BeforeClosing(object sender, FormClosingEventArgs e) {
            this.controller.BeforeClosing(sender, e);
        }

        private void ImportFileHandling(object sender, EventArgs e) {
            this.controller.ImportFileHandling(sender, e, this.txtImportFileName.Text, this.txtCompany.Text);
            this.pgBarIsInUse.Value = 0;
        }

        private void ImportFileSelection(object sender, EventArgs e) {
            this.txtImportFileName.Text =  this.controller.GetImportFileName(sender, e);
            if (this.txtImportFileName.Text != null && this.txtImportFileName.Text.Length > 0) {
                this.MyModel = this.controller.GetMySheets(this.txtImportFileName.Text);
                this.bsMySheets.DataSource = this.MyModel;
                this.txtCompany.Text = this.controller.GetCompany(this.txtImportFileName.Text);
                this.btnOpenFile.Enabled = true;
            }
        }

        private void OpenFile(object sender, EventArgs e) {
            this.controller.OpenFile(sender, e, this.txtImportFileName.Text);
        }

        public void ReloadData(List<ImportBMDModel> model) {
            this.MyModel = model;
            this.bsMySheets.DataSource = this.MyModel;
        }

        #endregion

        #region Overrides

        public override string ToString() {
            return this.Text;
        }
        
        #endregion
        
    }
}
